function check_new_sms_ajax(){
var Comet = function(options){
	this.init(options);
};
Comet.prototype = {
	constructor: Comet,
	init:function(options){
		this.options = {
			url:"",
			callback:function(){}
		}
		this.options = $.extend(this.options,options||{});
		this.url = this.options.url;
		this.callback = this.options.callback;
		this.timestamp = 0;
		this.noerror = true;
		this.lock = true;
	},
	connect: function(){
		this.lock = false;
		this.ajaxLoop();
	},
  	disconnect: function(){
		this.lock = true;
	},
	ajaxLoop: function(){		
		if(this.url && !this.lock){
			var _this = this;
			$.ajax({
				url:_this.url,
				type:'get',
				//data:'timestamp=' + _this.timestamp + '&user=admin',
				dataType:'json',
				cache:false,
				success:function(json){	
					if(json != null){
						_this.timestamp = json['timestamp'];
						
						_this.handleResponse(json);//执行回调，并传递JSON数据
						
						_this.noerror = true;
					}
				},
				complete:function(){
					
					if (_this.noerror){
						
						//_this.ajaxLoop();
						setTimeout(function(){_this.ajaxLoop()}, 2000); 
					}else{
						// if a connection problem occurs, try to reconnect each 2 seconds
						setTimeout(function(){_this.ajaxLoop()}, 2000); 
					}
					_this.noerror = false;
				}
			})
		}
	},
  	handleResponse: function(response){
    	this.callback(response);
  	},

	doRequest: function(request){
		if(this.url && !this.lock){
			$.get(this.url, { 'msg': request } ); 
		}
	}
}
var comet = new Comet({
	url:window.PROJECT_PATH+"sms/checkSms",
	callback:function(response){
		if(response.msg.length > 0){
			var refresh_email_s = false;
			var refresh_notify_s = false;
			var refresh_workflow_s = false;
			for(var i = 0; i<response.msg.length; i++) {
				if(response.msg[i].alerttype == 0){
					$.messager.show({
						title:'['+(i+1)+'/'+response.msg.length+']'+smstypestr(response.msg[i].smstype)+'提醒',
						msg:response.msg[i].content,
						timeout:5000,
						showType:'slide'
					});
					
				}else if(response.msg[i].alerttype == 1){
					$.messager.show({
						title:'['+(i+1)+'/'+response.msg.length+']'+smstypestr(response.msg[i].smstype)+'提醒',
						msg:response.msg[i].content,
						showType:'fade',
						style:{
							right:'',
							bottom:''
						}
					});
				}else if(response.msg[i].alerttype == 2){
					$.messager.alert('['+(i+1)+'/'+response.msg.length+']'+smstypestr(response.msg[i].smstype)+'提醒',response.msg[i].content,'info');
				}
				
				if(parseInt(response.msg[i].smstype) == 2){
					refresh_email_s = true;
				}
				if(parseInt(response.msg[i].smstype) == 3){
					refresh_notify_s = true;
				}
				if(parseInt(response.msg[i].smstype) == 4){
					refresh_workflow_s = true;
				}
			}
			
			$("#messagemp3").append("<object id='sms_sound' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='0' height='0'><param name='movie' value='/yjoa/data/other/wav/11.swf'><param name=quality value=high><embed id='sms_sound' src='/yjoa/data/other/wav/11.swf' width='0' height='0' quality='autohigh' wmode='opaque' type='application/x-shockwave-flash' plugspace='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed></object>");
			
			if(refresh_email_s){
				module_refresh_sms('收件箱','email_in_list');
			}
			if(refresh_notify_s){
				module_refresh_sms('收件箱','notify_in_list');
			}
			if(refresh_workflow_s){
				module_refresh_sms('工作流','workflow_list');
			}
		}
		//$('#messagerContent').append('<div>' + response['msg'] + '</div>');
	}
});
comet.connect();
$("#send").click(function(){
	comet.doRequest($('#clientUser').val()+$('#word').val());
	$('#word').val('');
})
$("#stop").click(function(){
	comet.disconnect();
})
}